package QuicktHit;

public class Game {
    private Player player;

    public Game(Player player){
        this.player=player;
    }

    public String printStr(){
      String rand="";
        for (int i=0;i<LevelParam.levels[player.getLevelNo()-1].getStrLength();i++){
             rand=rand+(char)(Math.random()*(127-32)+32);
            System.out.print(rand+"");
        }
           return rand ;
    }

    public void printResult(String out,String in)
    {
        boolean ok;
        if (out.equals(in)){
           ok=true;
        }else{
            ok=false;
        }
        if (ok){
           long startTime=System.currentTimeMillis();
            if ((startTime - player.getStartTime()) > LevelParam.levels[player.getLevelNo()-1].getTimeLimit()) {
                System.out.println("你输的太慢，已经超时了，退出");
                System.exit(1);
            }else{
                player.setCurrScore(player.getCurrScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());//计算积分
                player.setElaspsedTime((int)((startTime-player.getStartTime())/1000));//计算已用时间
                System.out.println("输入正确,你的级别:"+player.getLevelNo()+",你的积分:"+player.getCurrScore()+",已用时间:"+player.getElaspsedTime()+"秒");
                if (player.getLevelNo()==6){
                    int score=LevelParam.levels[player.getLevelNo()-1].getPerScore()*LevelParam.levels[player.getLevelNo()-1].getStrTimse();//计算闯关分数
                    if (player.getCurrScore()==score){
                        System.out.println("你已闯关成功，恭喜!");
                        System.exit(0);
                    }
                }
            }
        }else{
            System.out.println("输入有误,退出");
            System.exit(1);
        }
    }
}
